import axios from 'axios'
import qs from 'qs'
//添加请求拦截器
axios.interceptors.request.use((request) => {
  if (typeof request.data != "object") {
    return request;
  }
  //http://192.168.35.207:8080/api/file 
  if(/file/.test(request.url)){
    // request.headers["Content-Type"] = "application/x-www-form-urlencoded";
    request.headers["dfs_app_token"] = "5caaf9f0-9a8a-437d-a3f4-684b3f82d062";
    request.headers["dfs_app"] = "test_app";
    request.headers["dfs_group_id"] = "21";
    request.data = qs.stringify(request.data, {allowDots: true});
  }
    return request;
  })

//添加响应拦截器，响应拦截器会在then/catch处理之前执行
axios.interceptors.response.use((response) => {
  return response.data;
}, function (error) {
  return Promise.reject({
    code: "-999",
    msg: `[${error.response.status}]网络请求失败，请重试`,
    data: {
      status: error.response.status,
      statusText: error.response.statusText,
      error
    }
  });
});
